package vista;

import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaCategoria extends javax.swing.JFrame {
    private controlador.ControladorCategoria control;

   
    public VentanaCategoria() {
        initComponents();
        control= new controlador.ControladorCategoria(this);
        addAction();
    }

    public void addListener(ActionListener escuchador){
        btnSalir.addActionListener(escuchador);
        btnRegistrar.addActionListener(escuchador);
        btnCancelar.addActionListener(escuchador);
    }

    public void addAction(){
        btnSalir.setActionCommand("Salir");
        btnRegistrar.setActionCommand("Registrar");
        btnCancelar.setActionCommand("Cancelar");
    }
    
    public void limpiar(){
        txtCodigo.setText("");
        txtDescripcion.setText("");
    }

    public boolean hayVacios(){
        for (JTextField texto: getTextos()){
            if(texto.getText().equals("")){
                JOptionPane.showMessageDialog(new JFrame(),"Campos vacios","Cari Burguer",JOptionPane.INFORMATION_MESSAGE);
                return true;
            }
       }
        return false;
    }

    public boolean codigoValido(){
        try{
            if(Double.parseDouble(txtCodigo.getText())<=0){
                txtCodigo.setText("");
                JOptionPane.showMessageDialog(new JFrame(),"El codigo es invalido","Cari Burguer",JOptionPane.WARNING_MESSAGE);
                return false;
           }
       }catch(NumberFormatException ex){
           JOptionPane.showMessageDialog(new JFrame(),"El codigo es invalido","Cari Burguer",JOptionPane.WARNING_MESSAGE);
           return false;
       }
    return true;
    }

    public LinkedList<JTextField> getTextos() {
        LinkedList<JTextField> v = new LinkedList<JTextField>();
        return v;
    }

    public JTextField getTxtCodigo() {
        return txtCodigo;
    }

    public JTextField getTxtDescripcion() {
        return txtDescripcion;
    }


    @SuppressWarnings("unchecked")
   
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setLayout(null);
        {
        	txtDescripcion = new javax.swing.JTextField();
        	jPanel1.add(txtDescripcion);
        	txtDescripcion.setBounds(166, 74, 200, 22);
        }
        {
        	txtCodigo = new javax.swing.JTextField();
        	jPanel1.add(txtCodigo);
        	txtCodigo.setBounds(167, 37, 200, 22);
        }
        jPanel1.add(txtCodigo);

        jLabel1.setFont(new java.awt.Font("Ubuntu",1,15)); // NOI18N
        jLabel1.setText("Codigo");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(24, 39, 112, 23);
        jPanel1.add(txtDescripcion);

        jLabel3.setFont(new java.awt.Font("Ubuntu",1,15)); // NOI18N
        jLabel3.setText("Descripcion");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(22, 72, 132, 24);
        {
        	btnRegistrar = new javax.swing.JButton();
        	jPanel1.add(btnRegistrar);
        	btnRegistrar.setFont(new java.awt.Font("Ubuntu",1,15)); // NOI18N
        	btnRegistrar.setText("Guardar");
        	btnRegistrar.setBounds(22, 121, 100, 23);
        }
        {
        	btnCancelar = new javax.swing.JButton();
        	jPanel1.add(btnCancelar);
        	btnCancelar.setFont(new java.awt.Font("Ubuntu",1,15)); // NOI18N
        	btnCancelar.setText("Limpiar");
        	btnCancelar.setBounds(141, 121, 100, 23);
        }
        {
        	btnSalir = new javax.swing.JButton();
        	jPanel1.add(btnSalir);
        	btnSalir.setFont(new java.awt.Font("Ubuntu",1,15)); // NOI18N
        	btnSalir.setText("Salir");
        	btnSalir.setBounds(266, 121, 100, 23);
        }
        {
        	jLabel2 = new javax.swing.JLabel();
        	jPanel1.add(jLabel2);
        	jLabel2.setFont(new java.awt.Font("Ubuntu",1,15)); // NOI18N
        	jLabel2.setText("Categoria");
        	jLabel2.setBounds(155, 7, 99, 23);
        	jLabel2.setBackground(new java.awt.Color(255,255,255));
        }
        
        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 401, 171);
        jPanel1.setBackground(new java.awt.Color(255,255,255));

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        this.setBounds(0, 0, 399, 194);
        getContentPane().setBackground(new java.awt.Color(255,255,255));
        this.setTitle("Registrar Categoria");
    }// </editor-fold>//GEN-END:initComponents
   
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaCategoria().setVisible(true);
            }
        });
    }

    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnRegistrar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtDescripcion;


}
